/******************************************************************************
 * Copyright 2023 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#pragma once

#include "modules/canbus_vehicle/x3epro/proto/x3epro.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"

namespace apollo {
namespace canbus {
namespace x3epro {

class Securitybrakecommand44 : public ::apollo::drivers::canbus::ProtocolData<
                    ::apollo::canbus::X3epro> {
 public:
  static const int32_t ID;

  Securitybrakecommand44();

  uint32_t GetPeriod() const override;

  void Parse(const std::uint8_t* bytes, int32_t length,
                     X3epro* chassis) const override;

  void UpdateData(uint8_t* data) override;

  void Reset() override;

  // config detail: {'bit': 0, 'is_signed_var': False, 'len': 1, 'name': 'AEB_LeadBrakeCmd', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'bool'}
  Securitybrakecommand44* set_aeb_leadbrakecmd(bool aeb_leadbrakecmd);

  // config detail: {'bit': 23, 'is_signed_var': False, 'len': 8, 'name': 'CAN_Brake_Command', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  Securitybrakecommand44* set_can_brake_command(int can_brake_command);

  // config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'Security_DriverCmd_AliveCounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  Securitybrakecommand44* set_security_drivercmd_alivecounter(int security_drivercmd_alivecounter);

  // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'Security_DriverCmd_CheckSum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  Securitybrakecommand44* set_security_drivercmd_checksum(int security_drivercmd_checksum);

 private:

  // config detail: {'bit': 0, 'is_signed_var': False, 'len': 1, 'name': 'AEB_LeadBrakeCmd', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'bool'}
  void set_p_aeb_leadbrakecmd(uint8_t* data, bool aeb_leadbrakecmd);

  // config detail: {'bit': 23, 'is_signed_var': False, 'len': 8, 'name': 'CAN_Brake_Command', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  void set_p_can_brake_command(uint8_t* data, int can_brake_command);

  // config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'Security_DriverCmd_AliveCounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  void set_p_security_drivercmd_alivecounter(uint8_t* data, int security_drivercmd_alivecounter);

  // config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'Security_DriverCmd_CheckSum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
  void set_p_security_drivercmd_checksum(uint8_t* data, int security_drivercmd_checksum);

  bool aeb_leadbrakecmd(const std::uint8_t* bytes, const int32_t length) const;

  int can_brake_command(const std::uint8_t* bytes, const int32_t length) const;

  int security_drivercmd_alivecounter(const std::uint8_t* bytes, const int32_t length) const;

  int security_drivercmd_checksum(const std::uint8_t* bytes, const int32_t length) const;

 private:
  bool aeb_leadbrakecmd_;
  int can_brake_command_;
  int security_drivercmd_alivecounter_;
  int security_drivercmd_checksum_;
};

}  // namespace x3epro
}  // namespace canbus
}  // namespace apollo


